home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-12 | 17.1 KB | 578 lines | [TEXT/PJMM] |
- unit WEInterface;
-
- { WASTE PROJECT: }
- { Internal interface: constants, types and inline code }
-
- { Copyright © 1993-1994 Marco Piovanelli }
- { All Rights Reserved }
-
- interface
- uses
- LongCoords;
-
- const
-
- { result codes }
-
- weCantUndoErr = -9479; { undo buffer is clear }
- weUnknownObjectTypeErr = -9478; { specified object type was not registered }
- weObjectNotFoundErr = -9477; { no object found at specified offset }
-
- { alignment styles }
-
- weFlushLeft = -2;
- weFlushRight = -1;
- weFlushDefault = 0;
- weCenter = 1;
- weJustify = 2;
-
- { values for the edge parameter }
-
- kLeadingEdge = -1; { point is on the leading edge of a glyph }
- kTrailingEdge = 0; { point is on the trailing edge of a glyph }
- kObjectEdge = 2; { point is inside an embedded object }
-
- { control character codes }
-
- kObjectMarker = 1;
- kBackspace = 8;
- kEOL = 13;
- kArrowLeft = 28;
- kArrowRight = 29;
- kArrowUp = 30;
- kArrowDown = 31;
- kForwardDelete = 127;
-
- { bit equates for QuickDraw styles }
-
- tsBold = 0;
- tsItalic = 1;
- tsUnderline = 2;
- tsOutline = 3;
- tsShadow = 4;
- tsCondense = 5;
- tsExtend = 6;
-
- { bit equates for the tsFlags field of the WETextStyle record }
-
- tsTSMHilite = 4; { set if style run is part of active input area }
- tsTSMSelected = 5; { set for selected raw/converted text }
- tsTSMConverted = 6; { set for converted text, clear for raw text }
- tsRightToLeft = 7; { specifies style run direction }
-
- { bit equates for the mode parameter in WESetStyle and WEContinuousStyle }
-
- kModeFont = 0;
- kModeFace = 1;
- kModeSize = 2;
- kModeColor = 3;
- kModeAddSize = 4;
- kModeToggleFace = 5;
- kModeReplaceFace = 6;
- kModeObject = 14;
- kModeFlags = 15;
-
- { values for the mode parameter in WESetStyle and WEContinuousStyle }
-
- weDoFont = $0001;
- weDoFace = $0002;
- weDoSize = $0004;
- weDoColor = $0008;
- weDoAll = weDoFont + weDoFace + weDoSize + weDoColor;
- weDoAddSize = $0010;
- weDoToggleFace = $0020;
- weDoReplaceFace = $0040;
- weDoObject = $4000;
- weDoFlags = $8000;
-
- { values for WEFeatureFlag action parameter }
-
- weBitClear = 0; { disables the specified feature }
- weBitSet = 1; { enables the specified feature }
- weBitTest = -1; { returns the current setting of the specified feature }
-
- { bit equates for the flags field in the WE record }
- { bits 0..15 can be used to turn on and off specific features with WEFeatureFlag }
- { bits 16..31 are used internally and should not be modified }
-
- weFHasColorQD = 31; { Color QuickDraw is available }
- weFHasTextServices = 30; { Text Services Manager is available }
- weFNonRoman = 29; { At least one non-Roman script is enabled }
- weFDoubleByte = 28; { A double-byte script is installed }
- weFCaretVisible = 24; { Caret is currently visible }
- weFMouseTracking = 23; { Set internally during mouse tracking }
- weFAnchorIsEnd = 22; { Anchor offset is selEnd }
- weFUseNullStyle = 21; { A null style is associated with the empty selection }
- weFActive = 20; { TRUE if text pane is active }
- weFHilited = 19; { TRUE if text pane is highlighted (for Drag & Drop) }
- weFCanAcceptDrag = 18; { The drag in the text pane can be accepted }
- weFDragCaretVisible = 17; { Drag caret is currently visible }
-
- weFDrawOffscreen = 11; { Draw text offscreen for smoother visual results }
- weFUseTempMem = 10; { Use temporary memory }
- weFInhibitRecal = 9; { If set, recals and redraws are inhibited }
- weFDragAndDrop = 8; { Text drag-and-drop }
- weFIntCutAndPaste = 7; { Intelligent Cut & Paste }
- weFUndoSupport = 6; { Support Undo/Redo }
- weFOutlineHilite = 2; { Outline selection range when text pane is inactive }
- weFAutoScroll = 0; { Automatically scroll text when cursor is outside pane }
-
- { masks for setting the feature bits }
-
- weDoAutoScroll = $0001; { 1 << weFAutoScroll }
- weDoOutlineHilite = $0004; { 1 << weFOutlineHilite }
- weDoUndoSupport = $0040; { 1 << weFUndoSupport }
- weDoIntCutAndPaste = $0080; { 1 << weFIntCutAndPaste }
- weDoDragAndDrop = $0100; { 1 << weFDragAndDrop }
- weDoInhibitRecal = $0200; { 1 << weFInhibitRecal }
- weDoUseTempMem = $0400; { 1 << weFUseTempMem }
- weDoDrawOffscreen = $0800; { 1 << weFDrawOffscreen }
-
- { scrap types }
-
- kTypeText = 'TEXT';
- kTypeStyles = 'styl';
- kTypeSoup = 'SOUP';
-
- { selectors for WEGetInfo/WESetInfo }
-
- weClickLoop = 'clik';
- weCurrentDrag = 'drag';
- weLineArray = 'line';
- wePort = 'port';
- weRefCon = 'refc';
- weRunArray = 'runa';
- weScrollProc = 'scrl';
- weStyleTable = 'styl';
- weText = 'text';
- weTranslateDragHook = 'xdrg';
- weTSMDocumentID = 'tsmd';
- weTSMPostUpdate = 'post';
- weTSMPreUpdate = 'pre ';
-
- { possible values returned by WEIntelligentPaste }
-
- weDontAddSpaces = 0;
- weAddSpaceOnLeftSide = -1;
- weAddSpaceOnRightSide = 1;
-
- { values for WEAllocate allocFlags parameter }
-
- kAllocClear = $0001; { clear handle after allocation }
- kAllocTemp = $0002; { use temporary memory if available }
-
- { other miscellaneous constants }
-
- kCaretWidth = 1; { width of the caret, in pixels }
- kMinFontSize = 1; { minimum valid value for the font size }
- kMaxFontSize = maxint; { maximum valid value for the font size }
- kOneToOneScaling = $00010001; { 1:1 scaling ratio }
- kInvalidOffset = -1; { used to flag an invalid or nonexistent offset }
- kNullDrag = 0; { null or nonexistent drag reference }
- kNullObject = 0; { null object reference }
-
- type
-
- WEChars = packed array[0..999999] of Char;
- WECharsPtr = ^WEChars;
- WECharsHandle = ^WECharsPtr;
-
- DoubleByte = packed record
- firstByte: SignedByte;
- secondByte: SignedByte;
- end; { DoubleByte }
-
- WEFieldDescriptor = record
- fOffset: Integer;
- fLength: Integer;
- end; { WEFieldDescriptor }
-
- WELookupTableElement = record
- selector: OSType;
- desc: WEFieldDescriptor;
- end; { WELookupTableElement }
-
- WELookupTable = array[0..0] of WELookupTableElement;
-
- WETextStyle = record
- case Integer of
- 0: (
- tsFont: Integer;
- tsFace: SignedByte;
- tsFlags: SignedByte;
- tsSize: Integer;
- tsColor: RGBColor;
- );
- 1: (
- tsTEStyle: TextStyle; { TextEdit style attributes }
- tsObject: LongInt; { embedded object reference }
- );
- end; { WETextStyle }
- WETextStylePtr = ^WETextStyle;
-
- TERunAttributes = record
- runHeight: Integer;
- runAscent: Integer;
- runTEStyle: TextStyle;
- end; { TERunAttributes }
- TERunAttributesPtr = ^TERunAttributes;
-
- TEStyleScrapElement = record
- scrpStartChar: LongInt;
- scrpTEAttrs: TERunAttributes;
- end; { TEStyleScrapElement }
- TEStyleScrapElementPtr = ^TEStyleScrapElement;
-
- TEStyleScrap = record
- scrpNStyles: Integer;
- scrpStyleTab: array[0..0] of TEStyleScrapElement;
- end;
- TEStyleScrapPtr = ^TEStyleScrap;
- TEStyleScrapHandle = ^TEStyleScrapPtr;
-
- WERunAttributes = record
- case Integer of
- 0: (
- runHeight: Integer; { run height (ascent + descent + leading) }
- runAscent: Integer; { font ascent }
- runStyle: WETextStyle;
- );
- 1: (
- runTEAttrs: TERunAttributes;
- );
- end; { WERunAttributes }
- WERunAttributesPtr = ^WERunAttributes;
-
- WERunInfo = record
- runStart: LongInt;
- runEnd: LongInt;
- runAttrs: WERunAttributes;
- end; { WERunInfo }
- WERunInfoPtr = ^WERunInfo;
-
- GrafPort1 = record
- device: Integer;
- portBits: BitMap;
- portRect: Rect;
- visRgn: RgnHandle;
- clipRgn: RgnHandle;
- bkPat: Pattern;
- fillPat: Pattern;
- pnLoc: Point;
- pnSize: Point;
- pnMode: Integer;
- pnPat: Pattern;
- pnVis: Integer;
- txFont: Integer;
- txFace: SignedByte;
- filler: SignedByte;
- txMode: Integer;
- txSize: Integer;
- spExtra: Fixed;
- fgColor: LongInt;
- bkColor: LongInt;
- colrBit: Integer;
- patStretch: Integer;
- picSave: Handle;
- rgnSave: Handle;
- polySave: Handle;
- grafProcs: QDProcsPtr;
- end; { GrafPort1 }
- GrafPtr1 = ^GrafPort1;
-
- QDEnvironment = record
- envPort: GrafPtr;
- envPen: PenState;
- envStyle: WETextStyle;
- envMode: Integer;
- end; { QDEnvironment }
-
- TEStyleScrapPair = record
- first: TEStyleScrapElement;
- second: TEStyleScrapElement;
- end; { TEStyleScrapPair }
- TEStyleScrapPeek = ^TEStyleScrapPair;
-
- RunArrayElement = record
- runStart: LongInt; { offset to first character in style run }
- styleIndex: LongInt; { index into style table }
- end; { RunArrayElement }
- RunArrayElementPtr = ^RunArrayElement;
- RunArrayElementHandle = ^RunArrayElementPtr;
-
- RunArrayPair = record
- first: RunArrayElement;
- second: RunArrayElement;
- end; { RunArrayPair }
- RunArrayPeek = ^RunArrayPair; { useful to "peek" at a portion of the run array }
-
- const
- kRunArrayMaxIndex = (maxLongInt div SizeOf(RunArrayElement)) - 1;
-
- type
- RunArray = array[0..kRunArrayMaxIndex] of RunArrayElement;
- RunArrayPtr = ^RunArray;
- RunArrayHandle = ^RunArrayPtr;
-
- StyleTableElement = record
- refCount: LongInt; { reference count }
- info: WERunAttributes; { style information }
- end; { StyleTableElement }
- StyleTableElementPtr = ^StyleTableElement;
- StyleTableElementHandle = ^StyleTableElementPtr;
-
- const
- kStyleTableMaxIndex = (maxint div SizeOf(StyleTableElement)) - 1;
-
- type
- StyleTable = array[0..kStyleTableMaxIndex] of StyleTableElement;
- StyleTablePtr = ^StyleTable;
- StyleTableHandle = ^StyleTablePtr;
-
- LineRec = record
- lineStart: LongInt; { offset to first character in line }
- lineOrigin: LongInt; { distance from destRect.top, in pixels }
- lineAscent: Integer; { maximum font ascent for this line, in pixels }
- lineSlop: Integer; { extra pixels needed to fill up the line }
- lineJustAmount: Fixed; { normalized slop value for justification }
- end; { LineRec }
- LinePtr = ^LineRec;
- LineHandle = ^LinePtr;
-
- LinePair = record
- first: LineRec;
- second: LineRec;
- end; { LinePair }
- LinePeek = ^LinePair; { useful to "peek" at a portion of the line array }
-
- const
- kLineArrayMaxIndex = (maxLongInt div SizeOf(LineRec)) - 1;
-
- type
- LineArray = array[0..kLineArrayMaxIndex] of LineRec;
- LineArrayPtr = ^LineArray;
- LineArrayHandle = ^LineArrayPtr;
-
- WERec = record
- port: GrafPtr; { graphics port }
- hText: Handle; { handle to the raw text }
- hLines: LineArrayHandle; { handle to the line array }
- hStyles: StyleTableHandle; { handle to the style table }
- hRuns: RunArrayHandle; { handle to the style run array }
- textLength: LongInt; { length of raw text block }
- nLines: LongInt; { number of lines }
- nStyles: LongInt; { number of distinct styles in the style table }
- nRuns: LongInt; { number of style runs in the style run array }
- viewRect: LongRect; { view rectangle }
- destRect: LongRect; { destination rectangle }
- selStart: LongInt; { start of selection range }
- selEnd: LongInt; { end of selection range }
- flags: LongInt; { 32 bits of miscellaneous flags }
- caretTime: LongInt; { time of most recent caret xoring }
- clickTime: LongInt; { time of most recent click }
- clickLoc: LongInt; { byte offset of most recent click }
- anchorStart: LongInt; { anchor word start }
- anchorEnd: LongInt; { anchor word end }
- clickLoop: ProcPtr; { click loop callback }
- unused1: SignedByte; { unused }
- clickEdge: SignedByte; { edge of character hit by most recent click }
- unused2: SignedByte; { unused }
- firstByte: SignedByte; { first byte of a double-byte character }
- offscreenPort: GrafPtr; { offscreen graphics world }
- viewRgn: RgnHandle; { handle to the view region }
- scrollProc: ProcPtr; { scroll callback }
- clickCount: Integer; { multiple click count }
- alignment: Integer; { alignment style }
- refCon: LongInt; { reference value for client use }
- tsmReference: Ptr; { Text Services Manager document ID }
- tsmAreaStart: LongInt; { start of active inline input area }
- tsmAreaEnd: LongInt; { end of active inline input area }
- tsmPreUpdate: ProcPtr; { called before handling a TSM updt event }
- tsmPostUpdate: ProcPtr; { called after handling a TSM updt event }
- currentDrag: LongInt; { reference of drag being tracked by _WEDrag }
- dragCaretOffset: LongInt; { offset to caret displayed during a drag }
- translateDragHook: ProcPtr; { drag translation hook }
- hActionStack: Handle; { action stack for undo }
- modCount: LongInt; { modification count }
- nullStyle: WERunAttributes; { style for null selection }
- end; { WERec }
- WEPtr = ^WERec;
- WEHandle = ^WEPtr;
-
-
- var
-
- { externally defined global variables }
-
- {$PUSH}
- {$J+}
-
- _WEMainSelectorTable: WELookupTable;
- _WEObjectHandlerSelectorTable: WELookupTable;
-
- {$POP}
-
- { routines defined in the implementation section of this unit }
-
- function _WEAllocate (blockSize: Size;
- allocFlags: Integer;
- var h: univ Handle): OSErr;
-
- {$IFC WASTE_DEBUG}
-
- procedure _WEAssert (condition: Boolean;
- message: string);
-
- {$ENDC}
-
- { ****** ASSEMBLY ROUTINES DEFINED IN WASTEUTILS.LIB ****** }
-
- procedure _WEForgetHandle (var h: univ Handle);
- function _WESetHandleLock (h: univ Handle;
- lock: Boolean): Boolean;
- procedure _WEBlockClr (blockPtr: Ptr;
- blockSize: LongInt);
- function _WEBlockCmp (block1, block2: Ptr;
- blockSize: LongInt): Boolean;
- function _WEInsertSlot (h: univ Handle;
- element: univ Ptr;
- insertAt: LongInt;
- slotSize: LongInt): OSErr;
- function _WERemoveSlot (h: univ Handle;
- removeAt: LongInt;
- slotSize: LongInt): OSErr;
- procedure _WEReorder (var a, b: LongInt);
- function _WEGetField (table: WELookupTable;
- selector: OSType;
- info: univ Ptr;
- structure: univ Ptr): OSErr;
- function _WESetField (table: WELookupTable;
- selector: OSType;
- info: univ Ptr;
- structure: univ Ptr): OSErr;
-
-
- { ****** USEFUL INLINE ASSEMBLY ****** }
-
- function %_NewHandle (blockSize: Size;
- var h: Handle): OSErr;
- inline
- $225F, { movea.l (sp)+, a1 }
- $201F, { move.l (sp)+, d0 }
- $A122, { _NewHandle }
- $3E80, { move.w d0, (sp) }
- $2288; { move.l a0, (a1) }
-
- function %_GetHandleSize (h: univ Handle): Size;
- inline
- $205F, { movea.l (sp)+, a0 }
- $A025, { _GetHandleSize }
- $2E80, { move.l d0, (sp) }
- $6A02, { bpl.s *+4 }
- $4297; { clr.l (sp) }
-
- function %_SetHandleSize (h: univ Handle;
- blockSize: Size): OSErr;
- inline
- $201F, { move.l (sp)+, d0 }
- $205F, { movea.l (sp)+, a0 }
- $A024, { _SetHandleSize }
- $3E80; { move.w d0, (sp) }
-
- procedure %_BlockMoveData (sourcePtr, destPtr: univ Ptr;
- byteCount: LongInt);
- inline
- $201F, { move.l (sp)+, d0 }
- $225F, { movea.l (sp)+, a1 }
- $205F, { movea.l (sp)+, d0 }
- $A22E; { _BlockMove, IMMED }
-
- function %_PtrAndHand (thePointer: Ptr;
- theHandle: Handle;
- theSize: Size): OSErr;
- inline
- $201F, { move.l (sp)+, d0 }
- $225F, { movea.l (sp)+, a1 }
- $205F, { movea.l (sp)+, a0 }
- $A9EF, { _PtrAndHand }
- $3E80; { move.w d0, (sp) }
-
- procedure %_TextFace (face: Integer);
- inline
- $A888; { _TextFace }
-
- function %_Gestalt (selector: OSType;
- var response: LongInt): OSErr;
- inline
- $225F, { movea.l (sp)+, a1 }
- $201F, { move.l (sp)+, d0 }
- $A1AD, { _Gestalt }
- $3E80, { move.w d0, (sp) }
- $2288; { move.l a0, (a1) }
-
- function %_LongMul (dummy, a, b: LongInt): LongInt;
- inline
- $486F, $0008, { pea 8(sp) ; push address of dummy }
- $A867, { _LongMul ; _LongMul returns a 64-bit result }
- $584F; { addq.w #4, sp ; throw away high long }
-
- procedure IgnoreBoolean (b: Boolean);
- inline
- $544F; { addq.w #2, sp }
-
- procedure IgnoreShort (w: Integer);
- inline
- $544F; { addq.w #2, sp }
-
- procedure IgnoreLong (l: LongInt);
- inline
- $584F; { addq.w #4, sp }
-
- implementation
-
- function _WEAllocate (blockSize: Size;
- allocFlags: Integer;
- var h: univ Handle): OSErr;
-
- { Allocate a new relocatable block. }
- { AllocFlags may specify whether the block should be cleared and whether }
- { temporary memory should be used. }
-
- var
- theHandle: Handle;
- begin
- theHandle := nil;
-
- { if kAllocTemp is specified, try tapping temporary memory }
- if (BitAnd(allocFlags, kAllocTemp) <> 0) then
- theHandle := TempNewHandle(blockSize, _WEAllocate);
-
- { if kAllocTemp isn't specified, or TempNewHandle failed, try with current heap }
- if (theHandle = nil) then
- _WEAllocate := %_NewHandle(blockSize, theHandle);
-
- { if kAllocClear is specified, zero the block }
- if (BitAnd(allocFlags, kAllocClear) <> 0) then
- if (theHandle <> nil) then
- _WEBlockClr(theHandle^, blockSize);
-
- { return handle through VAR parameter }
- h := theHandle;
-
- end; { _WEAllocate }
-
- {$IFC WASTE_DEBUG}
-
- procedure _WEAssert (condition: Boolean;
- message: string);
- begin
- if (condition = false) then
- begin
- message := Concat('Assertion Failed: ', message);
- DebugStr(message);
- end;
- end; { _WEAssert }
-
- {$ENDC}
-
- end.